﻿using SharpDX;

namespace MikadoShooter
{
    public class DrawBg : DrawBase
    {
        public DrawBg() : base(CalcVerticals(), new Vector4Bg(CalcVerticals()))
        {
        }

        public void Update(Vector4 currentColor,Vector4 nextColor)
        {
            Vector4Bg draw = (Vector4Bg)Vector4Base;

            SetColor(draw.GetIndex(eWall.Down), currentColor, nextColor);
            SetColor(draw.GetIndex(eWall.Up), currentColor, nextColor);

            SetColor(draw.GetIndex(eWall.Left), currentColor, currentColor);

            SetColor(draw.GetIndex(eWall.Right), nextColor, nextColor);

            SetColor(draw.GetIndex(eWall.DownLeft), currentColor, MixColor(currentColor, nextColor));
            SetColor(draw.GetIndex(eWall.DownRight), nextColor, MixColor(currentColor, nextColor));

            SetColor(draw.GetIndex(eWall.EndLine), AlphaColor(currentColor), AlphaColor(nextColor));
        }

        private static Vector4 MixColor(Vector4 inputStartColor, Vector4 inputEndColor)
        {
            Vector4 color = (inputStartColor+inputEndColor) / 2;
            color.W = 1.0f;
            return color;
        }

        private static Vector4 AlphaColor(Vector4 inputColor, float aplha = 0.3f)
        {
            Vector4 color = inputColor * aplha;
            color.W = 1.0f;
            return color;
        }

        private void SetColor(int index, Vector4 startColor, Vector4 endColor)
        {
            Data[index * 4 + 1] = startColor;
            Data[index * 4 + 3] = endColor;
        }

        private static int CalcVerticals()
        {
            return 7*2;
        }
    }
}